<?php

/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Create and output the page
 *
 * @author Norbert Gebert
 * @copyright Norbert Gebert 25.09.2012
 * @license GPL3
 *
 * @version 0.5b
 * @package Frontend
 * @subpackage global
 */
//error_reporting(0);
//ini_set('session.use_only_cookies', '1');
header("X-XSS-Protection: 1");
ini_set( 'session.cookie_httponly', 1 );
ini_set('session.use_trans_sid', '0');
// Start Session
session_name('customer');
session_start();

define('TOBBIVM', 1);
require_once('config.php');
date_default_timezone_set(PHP_TIMEZONE);

// Setting Language
include_once('module/class/language.class.php');
$language = new language('main', './language', LANGUAGE);

// Init plugin-class
include_once('module/class/xplugin.class.php');
$xplugin = new xplugin();

include_once('module/class/validate.class.php');
$validate = new validate;
include_once 'module/login/login.php';

// load Templateengine
include_once('module/quickskin/_lib/class.quickskin.php');

// load Messageengine
include_once('module/class/message.class.php');
$message = new message();

// Init Connection to Database with prepared Statements
include_once('module/database/MysqliDb.php');
$db = new db(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
db::getInstance()->setPrefix(DB_PREFIX);

// setting Domain
textdomain("main");
// Translate-File must be in ./language/$language/LC_MESSAGES/main.mo
// Make sure that the SID has been assigned by the server
// to make a possible session fixation attack ineffective

if (!isset($_SESSION['server_SIDx']) or !isset($_SESSION['cartIdx']))
{
	// Clear session
	session_unset();
	// Definitely go all the contents of the session are deleted
	$_SESSION = array();
	// New server-generated session ID
	session_regenerate_id();
	// hold status
	$_SESSION['server_SIDx'] = true;
	$_SESSION['activex'] = false;
	$_SESSION['levelx'] = 0;
	$login = false;
	$update = false;
	$_SESSION['cartIdx'] = md5(session_id());
}
if (!isset($_SESSION['customernamex']))
	$_SESSION['customernamex'] = '';
// include shopping-cart
include_once 'module/class/cart.class.php';
$cart = new cart(CURRENCY);
// Logout user
if (isset($_POST['logout']))
	resetUser();

// init pagepointer-class
include_once 'module/class/pagepointer.class.php';
$pagepointer = new pagepointer();

// Init and load plugin-setups
//include_once 'module/class/plugin.class.php';
//$plugin = new plugin();

// Call Startpage
$page = new QuickSkin('index.tpl.php');
include_once 'module/login/login.mod.php';
include_once 'module/login/login.php';
include_once('module/core.php');

// Config the Templateengine
$page->set('template_dir', TEMPLATE_PATH . '/');
$page->set('temp_dir', 'tmp/');
$page->set('cache_dir', 'tmp/');
$page->set('cache_lifetime', 1);
// Image-Path
$page->assign('tpl_img', TEMPLATE_PATH . '/images/');
$page->assign('url_img', URL . '/' . TEMPLATE_PATH . '/images/');
// Template Javascript-Path
$page->assign('tpl_js', TEMPLATE_PATH . '/module/js/');
$page->assign('url_js', URL . '/' . TEMPLATE_PATH . '/module/js/');
// Template CSS-Path
$page->assign('tpl_css', TEMPLATE_PATH . '/css/');
$page->assign('url_css', URL . '/' . TEMPLATE_PATH . '/css/');

$page->output();

pagepointer::setCurrentPage();
?>